﻿<div class="pagination">
    <ul>
        @if (Model.HasPreviousPage)
        {
            @Html.Raw("<li>")
            @Ajax.ActionLink("<<", "Index", new
       {
           page = 1,
           sortOrder = ViewBag.CurrentSortOrder,
           filter = ViewBag.CurrentFilter,
           Keyword = ViewBag.CurrentKeyword
       }, new AjaxOptions
       {
           UpdateTargetId = "main"
       })
            @Html.Raw("</li><li>");
            @Ajax.ActionLink("<上一页", "Index", new
       {
           page = Model.PageNumber - 1,
           sortOrder = ViewBag.CurrentSortOrder,
           filter = ViewBag.CurrentFilter,
           Keyword = ViewBag.CurrentKeyword
       }, new AjaxOptions
       {
           UpdateTargetId = "main"
       })
            @Html.Raw("</li>")
        }
        else
        {
            @:<li class="disabled"><a href="#"><<</a></li>
        @:<li class="disabled"><a href="#"><上一页</a></li>
                    }
        @{
            int num = Model.PageCount / 15;//总倍数
            int inum = 16;//显示数列
            int pn=(Model.PageNumber-1)/15;
            if (Model.PageNumber > num * 15)
            {
                inum = Model.PageCount % 15+1; //超出15余下显示的条目
            }
          
            
            for (int i = 1; i < inum; i++)
            {
                string pNumer = Convert.ToString(Model.PageNumber);

                if (i == (Model.PageNumber - pn*15))
                {
                    @Html.Raw("<li class='disabled'><a href='#'>" + pNumer + "</a>") 
                }
                else
                {
                    int curNum = (Model.PageNumber-1) / 15*15+i;
                    @Html.Raw("<li>");
                    @Ajax.ActionLink(curNum.ToString(), "Index", new
                    {
                        page = curNum,
                        sortOrder = ViewBag.CurrentSortOrder,
                        filter = ViewBag.CurrentFilter,
                        Keyword = ViewBag.CurrentKeyword
                    }, new AjaxOptions
                    {
                    UpdateTargetId = "main"
                    })     
                }
            @Html.Raw("</li>");
            }
        }
        @if (Model.HasNextPage)
        {
            @Html.Raw("<li>"); 
            @Ajax.ActionLink("下一页>", "Index", new
       {
           page = Model.PageNumber + 1,
           sortOrder = ViewBag.CurrentSortOrder,
           filter = ViewBag.CurrentFilter,
           Keyword = ViewBag.CurrentKeyword
       }, new AjaxOptions
       {
           UpdateTargetId = "main"
       })
            @Html.Raw("</li><li>");
            @Ajax.ActionLink(">>", "Index", new
       {
           page = Model.PageCount,
           sortOrder = ViewBag.CurrentSortOrder,
           filter = ViewBag.CurrentFilter,
           Keyword = ViewBag.CurrentKeyword
       }, new AjaxOptions
       {
           UpdateTargetId = "main"
       })
        }
        else
        {
            @:<li class="disabled"><a href="#">下一页></a></li>
         @:<li class="disabled"><a href="#">>></a></li>
                        }
    </ul>
</div>
